package com.yh.csx.bsf.flow.core.base;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: chejiangyi
 * @version: 2019-10-23 17:48
 * 流程模型实体定义
 **/
@Data
public class Model {
//    private String name;
//    private String title;
//    private List<Variable> variables;
//    private List<Node> nodes;
//    private String pc_url;DistributeModeEnum
//    private String mobile_url;
//    private FormPermission formPermission;
//    private int version;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class RouteResult{
        private String node;
        private String title;
    }


    /**
     * 表单权限
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XStreamAlias("FormPermission")
    public static class FormPermission{
        @XStreamAsAttribute
        private String node;
        @XStreamAsAttribute
        private String variableKey;
        @XStreamAlias("permission")
        @XStreamAsAttribute
        private PermissionEnum permissionEnum;
        @XStreamAlias("ChooseUsers")
        private List<ChooseUser> chooseUsers;
    }

    public enum ModelType{
        inface(0,"接口流程"),
        normal(1,"普通流程"); 

        public int Value;
        public String Desc;

        ModelType(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }
    
    public enum PermissionEnum{
        read(0,"读权限"),
        write(1,"写权限"),
        hide(2,"隐藏");

        public int Value;
        public String Desc;

        PermissionEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }

    @Data
    @XStreamAlias("Node")
    public static class Node{
        @XStreamAlias("type")
        @JsonProperty("type")
        @XStreamAsAttribute
        private TypeEnum typeEnum;
        @XStreamAsAttribute
        private String title;
        @XStreamAsAttribute
        private String location;
        
        /**
         * 开始脚本
         */
        @XStreamAlias("BeginScript")
        private String beginScript;
        /**
         * 结束脚本
         */
        @XStreamAlias("EndScript")
        private String endScript;
        /**
         * 审批用户规则
         */
        @XStreamAlias("ApproveUser")
        private ApproveUser approveUser;
        /**
         * 路由
         */
        @XStreamAlias("Routes")
        private List<Route> routes;
        /**
         * 开始通知
         */
        @XStreamAlias("startNotify")
        @XStreamAsAttribute
        private NotifyEnum startNotify;
        /**
         * 结束通知
         */
        @XStreamAlias("endNotify")
        @XStreamAsAttribute
        private NotifyEnum endNotify;
        /**
         * 超时规则
         */
        @XStreamAlias("TimeOutRules")
        private ArrayList<TimeOutRule> timeOutRules;
        /**
         * 审批结果
         */
        @XStreamAlias("ApproveResults")
        private ArrayList <String> approveResults;
    }
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XStreamAlias("Route")
    public static class Route{
        @XStreamAsAttribute
        private String next;
        @XStreamAsAttribute
        private String title;
        @XStreamAlias("Script")
        private String script;

    }

    public enum TypeEnum{
        Man(0,"人工"),
        Auto(1,"自动"),
        Start(2,"开始"),
        End(3,"结束");
        public int Value;
        public String Desc;

        TypeEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }

    public enum NotifyEnum{
        None(0,"无"),
        SMS(1,"短信"),
        Mail(2,"邮件");
        public int Value;
        public String Desc;

        NotifyEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }

    /**
     * 分发模式
     */
    public enum DistributeModeEnum{
        /**
         * 一次性
         */
        Once(0,"一次性分发"),
        /**
         * 一个个分发
         */
        OneByOne(1,"逐个分发");
        public int Value;
        public String Desc;

        DistributeModeEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }

    /**
     * 筛选方式
     */
    public enum FilterModeEnum{
        Random(0,"随机"),
        Order(1,"顺序");
        public int Value;
        public String Desc;

        FilterModeEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }

    /**
     * 审批用户
     */
    @Data
    public static class ApproveUser{
        @XStreamAlias("distributeMode")
        @XStreamAsAttribute
        private DistributeModeEnum distributeModeEnum;
        @XStreamAlias("filterMode")
        @XStreamAsAttribute
        private FilterModeEnum filterModeEnum;
        @XStreamAsAttribute
        private int approveNum;
        @XStreamAlias("ChooseUsers")
        private List<ChooseUser> chooseUsers;
    }

//    /**
//     * 审批结果
//     */
//    @Data
//    public static class ApproveResult{
//        /**
//         * [转交]表示转交操作
//         */
//        private String text;
//    }

    /**
     * 超时规则
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XStreamAlias("TimeOutRule")
    public static class TimeOutRule{
        @XStreamAsAttribute
        private int timeSpan;
        @XStreamAlias("timeoutDealWay")
        @XStreamAsAttribute
        private TimeoutDealWayEnum timeoutDealWayEnum;
        /**
         * 根据类型,值为:短信，邮件，用户id，脚本
         */
        private String valueScript;
    }

    public enum TimeoutDealWayEnum{
        Notify(0,"发送消息"),
        Transfer(1,"转交"),
        Script(2,"脚本");
        public int Value;
        public String Desc;

        TimeoutDealWayEnum(int value,String desc){
            this.Value = value;
            this.Desc = desc;
        }
    }
}
